home *** CD-ROM | disk | FTP | other *** search
- ## -*-Tcl-*-
- # ###################################################################
- # Part of AlphaTcl - core Tcl engine
- #
- # FILE: "vcsCore.tcl"
- # created: 03/23/2000 {10:59:22 AM}
- # last update: 1/8/2001 {10:36:27 AM}
- #
- # ========================================================================
- # Copyright (c) 1998-2001 Jon Guyer, Vince Darley
- # All rights reserved
- # ========================================================================
- # Permission to use, copy, modify, and distribute this software and its
- # documentation for any purpose and without fee is hereby granted,
- # provided that the above copyright notice appear in all copies and that
- # both that the copyright notice and warranty disclaimer appear in
- # supporting documentation.
- #
- # The authors disclaim all warranties with regard to this software,
- # including all implied warranties of merchantability and fitness. In
- # no event shall the authors be liable for any special, indirect or
- # consequential damages or any damages whatsoever resulting from loss of
- # use, data or profits, whether in an action of contract, negligence or
- # other tortuous action, arising out of or in connection with the use or
- # performance of this software.
- # ========================================================================
- #
- # For the moment this code is designed to work with Tcl 7.x as
- # well as 8.x, which is why namespaces aren't handled in the most
- # elegant way: we may not have them!
- # ###################################################################
- ##
-
- alpha::extension vcs 0.1a8 {
- namespace eval vcs {}
- # This allows us to attach version control information to any fileset
- fileset::attachNewInformation * [list global versionControlSystem] "Version Control System" No \
- "The version control system under which these files are placed" vcs::vcsSystemModified
- # The current version control system.
- newPref var versionControlSystem "No" vcs "" vcs::system "array"
- # Called when the user ctrl/cmd-clicks on the lock icon
- hook::register unlockHook vcs::manualUnlock *
- hook::register lockHook vcs::manualLock *
- # Add a version control prefs page, mapped to the 'vcs' storage
- package::addPrefsDialog versionControl vcs
- newPref flag addNameOfSystemToPopup 1 vcs
- } help {
- AlphaTcl's core version control functionality is provided by this
- package.
- }
-
- namespace eval vcs {}
-
- set vcs::system(No) vcs
-
- proc vcs::menuProc {item} {
- switch -- $item {
- lock {
- # Right now this just implements non-vcs connected
- # lock/unlock actions
- setWinInfo read-only 1
- }
- unlock {
- # Right now this just implements non-vcs connected
- # lock/unlock actions
- setWinInfo read-only 0
- }
- default {
- # add checkIn undoCheckout makeWritable checkOut
- # refetchReadOnly fetchReadOnly
- set name [win::Current]
- vcs::call $item $name
- vcs::syncLockStatus $name
- }
- }
- }
-
- proc vcs::vcsSystemModified {fset value} {
- hook::callAll vcsSystemModified $value $fset
- }
-
- proc vcs::register {type {ns ""}} {
- global vcs::system
- if {![string length $ns]} { set ns $type }
- set vcs::system($type) $ns
- }
-
- proc vcs::getNamespace {} {
- global vcs::system
- set vcs::system([vcs::getSystem])
- }
-
- proc vcs::getState {name} {
- return ""
- }
-
- proc vcs::getInfo {infoName} {
- return [fileset::getInformation [fileset::checkCurrent] $infoName]
- }
-
- proc vcs::getSystem {} {
- global vcsmodeVars
- set fset [fileset::checkCurrent]
- if {![string length $fset]} {
- if {[info exists vcsmodeVars(versionControlSystem)]} {
- return $vcsmodeVars(versionControlSystem)
- } else {
- return "No"
- }
- } else {
- return [fileset::getInformation $fset "Version Control System"]
- }
- }
-
- proc vcs::call {what args} {
- set ns [vcs::getNamespace]
- if {[catch {eval ${ns}::${what} $args} err]} {
- message $err
- }
- return $err
- }
-
- proc vcs::syncLockStatus {name} {
- getFileInfo [win::StripCount $name] fileState
- getWinInfo winState
- if {$winState(read-only) != $fileState(readonly)} {
- setWinInfo read-only $fileState(readonly)
- }
- }
-
- proc vcs::manualUnlock {name} {
- vcs::call unlock $name
- }
-
- proc vcs::manualLock {name} {
- vcs::call lock $name
- }
-
- proc vcs::showDifferences {name} {
- }
-
- proc vcs::lock {name} {
- setWinInfo read-only 1
- }
-
- proc vcs::unlock {name} {
- setWinInfo read-only 0
- }
-
- proc vcs::checkIn {name} {
- }
-
- proc vcs::checkOut {name} {
- }
-
- proc vcs::undoCheckout {name} {
- }
-
- proc vcs::refetchReadOnly {name} {
- }
-
- proc vcs::otherCommands {state} {
- # nothing by default
- }
-
- # This is a callback routine for Alpha 8's VCS popup menu
- proc ckidMenu {ckid locked} {
- global menu::items
- set state [lindex [list "no-vcs" "checked-out" "read-only" "mro"] $ckid]
- set menu::items(ckid) [vcs::menuItems $state $locked]
- menu::buildOne ckid
- return "ckid"
- }
-
- # Used in a callback from Alpha 8 via the above proc, or directly
- # in Alphatk. An empty state means AlphaTcl has no idea how to
- # get any vcs information for this file (e.g. we're running
- # Alphatk), a state of 'no-cvs' means this file doesn't appear
- # to be under version control, but we should really double-check.
- proc vcs::menuItems {state locked} {
- global vcsmodeVars
- # ckid icon suite runs from 490 to 494
- # subtract 208 (why?!?) + 256
-
- if {$state == "" || $state == "no-cvs"} {
- # Unknown state
- set state [vcs::call getState [win::Current]]
- }
-
- if {[info exists vcsmodeVars(addNameOfSystemToPopup)]
- && $vcsmodeVars(addNameOfSystemToPopup)} {
- lappend res "\(using[vcs::getSystem]VCSystem"
- } else {
- set res [list]
- }
-
- # Active items should depend on whether we have a VCS system
- # active and on the state of the file.
- #
- # Currently 'read-only' means the file is either 'up-to-date'
- # or 'needs-patch', but we don't know which (it appears as if
- # the ckid resource doesn't give us enough information?).
-
- eval lappend res [vcs::call getMenuItems $state]
-
- if {[llength $res]} {
- lappend res "(-)"
- }
-
- if {$locked} {
- lappend res "unlock[icon::FromID 494]"
- } else {
- lappend res "lock[icon::FromID 493]"
- }
-
- # # Add any other items the vcs system wants to use
- # set extras [vcs::call otherCommands $state]
- # if {[llength $extras]} {
- # lappend res "(-)"
- # eval lappend res $extras
- # }
-
- set res
- }
-
- ##
- # -------------------------------------------------------------------------
- #
- # "vcs::getMenuItems" --
- #
- # Called when there is no active VC System
- # All items disabled.
- # -------------------------------------------------------------------------
- ##
- proc vcs::getMenuItems {state} {
- switch -- $state {
- "no-vcs" {
- lappend res "\(add…[icon::FromID 491]"
- }
- "checked-out" {
- lappend res \
- "\(checkIn…[icon::FromID 490]" \
- "\(undoCheckout[icon::FromID 491]" \
- "\(makeWritable[icon::FromID 492]" \
- "(-)" \
- "\(showDifferences"
- }
- "read-only" {
- lappend res \
- "\(checkOut…[icon::FromID 490]" \
- "\(refetchReadOnly[icon::FromID 491]" \
- "\(makeWritable[icon::FromID 492]" \
- "(-)" \
- "\(showDifferences"
- }
- "mro" {
- lappend res \
- "\(checkOut…[icon::FromID 490]" \
- "\(fetchReadOnly[icon::FromID 491]" \
- "\(makeWritable[icon::FromID 492]" \
- "(-)" \
- "\(showDifferences"
- }
- "up-to-date" {
- lappend res \
- "\(checkOut…[icon::FromID 490]" \
- "\(makeWritable[icon::FromID 492]" \
- }
- "needs-patch" {
- lappend res \
- "\(refetchReadOnly[icon::FromID 491]" \
- "(-)" \
- "\(showDifferences"
- }
- "" {
- # no version control registered, or not possible
- # to place under version control with current
- # system
- set res {}
- }
- default {
- error "Bad response '$state' received from vcs system"
- }
- }
-
- return $res
- }
-
- ##
- # -------------------------------------------------------------------------
- #
- # "vcs::generalMenuItems" --
- #
- # General utility function.
- # Most VC Systems will use this to build the bulk of their items
- # -------------------------------------------------------------------------
- ##
- proc vcs::generalMenuItems {state} {
- switch -- $state {
- "no-vcs" {
- lappend res "add…[icon::FromID 491]"
- }
- "checked-out" {
- lappend res \
- "checkIn…[icon::FromID 490]" \
- "undoCheckout[icon::FromID 491]" \
- "\(makeWritable[icon::FromID 492]" \
- "(-)" \
- "showDifferences"
- }
- "read-only" {
- lappend res \
- "checkOut…[icon::FromID 490]" \
- "refetchReadOnly[icon::FromID 491]" \
- "makeWritable[icon::FromID 492]" \
- "(-)" \
- "showDifferences"
- }
- "mro" {
- lappend res \
- "checkOut…[icon::FromID 490]" \
- "fetchReadOnly[icon::FromID 491]" \
- "\(makeWritable[icon::FromID 492]" \
- "(-)" \
- "showDifferences"
- }
- "up-to-date" {
- lappend res \
- "checkOut…[icon::FromID 490]" \
- "makeWritable[icon::FromID 492]" \
- }
- "needs-patch" {
- lappend res \
- "refetchReadOnly[icon::FromID 491]" \
- "(-)" \
- "showDifferences"
- }
- "" {
- # no version control registered, or not possible
- # to place under version control with current
- # system
- set res {}
- }
- default {
- error "Bad response '$state' received from vcs system"
- }
- }
-
- return $res
- }
-